package com.jk.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/***
 * @ClassName: QueryWeatherController
 * @Description:TODO 天气查询接口
 * @Auther: TaiBai
 * @Date: 2021/7/2 11:07
 * @version : V1.0
 */
@Api(tags = "天气查询接口")
@RestController
@RequestMapping("QueryWeather")
public class QueryWeatherController {

    @Autowired
    private RestTemplate restTemplate;
    /*
    * @Author  TaiBai
    * @Description //TODO 根据城市名称调用天气接口
    * @Date 11:19 2021/7/2
    * @method  QueryWeather
    * @Param []
    * @return java.lang.String
    **/
    @ApiOperation(value = "天气查询接口", notes = "返回最近7天天气预报",produces ="city")
    @PostMapping("QueryWeather/{city}")
    public String QueryWeather(@PathVariable("city")@ApiParam("城市")String city) {
        String apiURL = "http://wthrcdn.etouch.cn/weather_mini?city=" + city;
        ResponseEntity<String> responseEntity = restTemplate.getForEntity(apiURL, String.class);
        if (200 == responseEntity.getStatusCodeValue()) {
            return responseEntity.getBody();
        } else {
            return "error with code : " + responseEntity.getStatusCodeValue();
        }
    }
}
